﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;

namespace ERP_RORZE_PRODUCT.Product.Quotation
{
    public partial class frm_QuotationAdd : DevExpress.XtraEditors.XtraForm
    {
        public event EventHandler Reload;
        DataTable dt;
        ClsQuationDAO clsQuationDAO = new ClsQuationDAO();
        QuotationTable b = new QuotationTable();
        public frm_QuotationAdd()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frm_QuotationAdd_Load(object sender, EventArgs e)
        {
            dt = clsQuationDAO.GetAllCustumerID();
            cbCustumerID.DataSource = dt;
            cbCustumerID.DisplayMember = "CustomerID";
            cbCustumerID.ValueMember = "CustomerID";
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtQuotationID.Text == "")
            {
                MessageBox.Show("Chưa nhập QuotationID");
            }
            else
            {
                b.QuotationID = txtQuotationID.Text;
                dt = clsQuationDAO.GetAllQuotationByID(b);
                int i = 0;
                foreach (DataRow r in dt.Rows)
                {
                    i++;
                }
                if (i > 0)
                {
                    MessageBox.Show("QuotationID đã có trong dữ liệu");
                }
                else 
                {
                    b.QuotationID = txtQuotationID.Text;
                    b.Date = dateDate.Value;
                    b.CustomerID = cbCustumerID.Text;
                    clsQuationDAO.InsertQuotation(b);
                    Reload(sender, e);
                }
            }
        }
    }
}